package com.myproject.musicrecommendationsystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.myproject.musicrecommendationsystem.domain.User;
import com.myproject.musicrecommendationsystem.service.UserService;
import com.myproject.musicrecommendationsystem.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户Controller

 */
@RestController
@RequestMapping("/system/user")
@Api(tags="用户管理(0729单禹铭)")
public class UserController
{
    @Autowired
    private UserService userService;

    /**
     * 查询用户列表
     */

    @GetMapping("/list")
    @ApiOperation("查询用户")
    public AjaxResult list(User user)
    {

        List<User> list = userService.selectUserList(user);
        return AjaxResult.success(list);
    }


    /**
     * 获取用户详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation("根据ID查询用户")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userService.selectUserById(id));
    }

    /**
     * 新增用户
     */

    @PostMapping("/add")
    @ApiOperation("新增用户")
    public AjaxResult add(@RequestBody User user)
    {
        return AjaxResult.success(userService.insertUser(user));
    }

    /**
     * 修改用户
     */

    @PutMapping("/update")
    @ApiOperation("修改用户")
    public AjaxResult edit(@RequestBody User user)
    {
        return AjaxResult.success(userService.updateUser(user));
    }

    /**
     * 删除用户
     */

	@DeleteMapping("/{ids}")
    @ApiOperation("删除用户")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return AjaxResult.success(userService.deleteUserByIds(ids));
    }
}
